package cn.kimming.rpc.remoting.proxy;

import cn.kimming.rpc.remoting.client.RpcClient;
import cn.kimming.rpc.remoting.client.RpcClientConfig;
import cn.kimming.rpc.common.constant.ProxyWay;
import cn.kimming.rpc.remoting.proxy.cglib.CglibRpcClientProxyFactory;
import cn.kimming.rpc.remoting.proxy.jdk.JDKRpcClientProxyFactory;

public class RpcProxyFactory {

    public static <T> T createClient(Class<T> type, RpcClientConfig config) {
        RpcClient rpcClient = new RpcClient(type.getCanonicalName(), config);
        ProxyWay proxyWay = config.getProxyWay();
        switch (proxyWay) {
            case JDK:
                return (T) JDKRpcClientProxyFactory.getRpcClientProxy(type, rpcClient);
            case CGLIB:
                return (T) CglibRpcClientProxyFactory.getRpcClientProxy(type, rpcClient);
        }
        return null;
    }
}
